package book.nettyinaction.ch11;

import io.netty.channel.*;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * 代码清单 11-11 使用 FileRegion 传输文件的内容
 */
public class Demo11FileRegion {

    public static void main(String[] args) throws FileNotFoundException {
        String file = null;
        Channel channel = null;
        FileInputStream in = new FileInputStream(file);
        FileRegion region = new DefaultFileRegion(in.getChannel(), 0, file.length());

        channel.writeAndFlush(region)
                .addListener(new ChannelFutureListener() {
                    @Override
                    public void operationComplete(ChannelFuture future) throws Exception {
                        if (!future.isSuccess()) {
                            Throwable cause = future.cause();
                            // Do something
                        }
                    }
                });
    }
}
